home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / oop_tp55.zip / LIST5_A.PAS < prev    next >
Pascal/Delphi Source File  |  1990-01-24  |  12KB  |  485 lines

  1. { Unit: Tags
  2.  
  3. Utilization notes:
  4.  
  5. 1. If no file name is supplied on the command line, the
  6.    program will print output to the screen.  If a file
  7.    name is supplied, the output will be directed to the
  8.    file.
  9.  
  10. 2. The object 'Quiet' controls program output
  11.    (including the opening and closing of output files.)
  12.    The procedure Quiet.On will turn output off and close
  13.    the output file, if one is specified.  Subsequent calls
  14.    to the procedure Quiet.Off will turn output back on and
  15.    append it to f.  The default status of Quiet is ON.
  16.  
  17. 3. Users wanting to write to a file must first
  18.    make sure Quiet is Off, and direct output to
  19.    the file f, as in the following example.
  20.  
  21.      if Quiet.IsOff then
  22.          writeln( f, 'Put your string here' );
  23.  
  24. 4. Programs using this unit should, at the end of the progam,
  25.    either explicitly make a call to Quiet.On or include the
  26.    line
  27.  
  28.        Close( f );
  29. }
  30.  
  31. { Specification for Tags class ***************************
  32.  
  33.   Variables:
  34.             TagNumber : String12;
  35.             Stores a tag number of up to 12 characters.
  36.  
  37.   Procedures:
  38.             .Init(( ATag : String12 );
  39.             ATag is stored in TagNumber.
  40.  
  41.   Descendant object types:
  42.             Digital
  43.             Analog              }
  44.  
  45. { Specification for Digital class ************************
  46.  
  47.   Variables:
  48.             Status : boolean;
  49.             Indicates whether digital object is ON or OFF.
  50.             ON denotes TRUE; OFF, FALSE.
  51.  
  52.   Procedures:
  53.             .Init( ATag : String12; AStatus : boolean );
  54.             ATag is stored in TagNumber; AStatus is stored
  55.             in Status.
  56.  
  57.             .PutStatus( AStatus : boolean );
  58.             Sets Status to AStatus.
  59.  
  60.   Functions:
  61.             .GetStatus : boolean;
  62.             Returns ON or OFF status of object.
  63.             If variable 'Quiet' (boolean) is ON, then
  64.             Status is not printed to screen; otherwise
  65.             the Status and TagNumber are printed to
  66.             the screen.
  67.  
  68.   Descendant object types:
  69.             DInput
  70.             DOutput          }
  71.  
  72. { Specification for Analog class *************************
  73.   Variables:
  74.             Value : Resolution;
  75.             Value must have a value between 0 and 4095.
  76.  
  77.             ZeroVal : real;
  78.             Engineering unit value corresponding to a Value
  79.             of 0.
  80.  
  81.             MaxVal : real;
  82.             Engineering unit value corresponding to a Value
  83.             of 4095.
  84.  
  85.             Slope : real;
  86.             A number calculated from the equation:
  87.    (MaxVal-ZeroVal)/(4095-0).
  88.  
  89.   Procedures:
  90.             .Init(( ATag : String12; AValue : Resolution;
  91.             Min, Max : real );
  92.             Storage as follows:
  93.    ATag -> TagNumber
  94.    AValue -> Value
  95.    Min -> ZeroVal
  96.    Max -> MaxVal
  97.  
  98.             .PutValue( AValue : real );
  99.             Converts AValue engineering units into counts
  100.             (between 0 and 4095) and stores in Value.
  101.  
  102.   Functions:
  103.             .GetValue : real;
  104.             Converts and returns the counts in Value to
  105.             engineering units.
  106.  
  107.   Descendant types:
  108.             None.       }
  109.  
  110. { Specification for DInput class *************************
  111.  
  112.   Variables:
  113.             Setpoint : real;
  114.             Contains a value at which something happens.
  115.  
  116.             Reading : real;
  117.             Contains an number that is compared to the
  118.             setpoint.
  119.  
  120.   Procedures:
  121.             .PutSetpoint( NewSetpoint : real );
  122.             Sets Setpoint to NewSetpoint.
  123.  
  124.             NOTE: .Init procedure is packaged with
  125.      descendant classes.
  126.  
  127.   Descendant object types:
  128.             HiSwitch
  129.             LoSwitch         }
  130.  
  131. { Specification for DOutput class ************************
  132.  
  133.     NO VARIABLES, NO PROCEDURES, NO FUNCTIONS
  134.     (see descendant object type)
  135.  
  136.   Descendant object types:
  137.             Pump        }
  138.  
  139. { Specification for HiSwitch class ************************
  140.  
  141.   Procedures:
  142. .Init(( ATag : string;
  143.         ASetpoint : real;
  144.         AReading : real);
  145. Storage as follows:
  146.   ATag -> TagNumber
  147.   ASetpoint -> Setpoint
  148. The value of AReading is stored in Reading
  149. using the .PutReading method.
  150.  
  151. .PutReading( NewReading : real);
  152. Store NewReading in Reading.  Set Status to
  153. ON if Reading >= Setpoint.
  154.  
  155.   Descendant object types:
  156. None.      }
  157.  
  158. { Specification for LoSwitch class ************************
  159.  
  160.   Procedures:
  161. .Init(( ATag : string;
  162.         ASetpoint : real;
  163.         AReading : real);
  164. Storage as follows:
  165.   ATag -> TagNumber
  166.   ASetpoint -> Setpoint
  167. The value of AReading is stored in Reading
  168. using the .PutReading method.
  169.  
  170. .PutReading( NewReading : real);
  171. Store NewReading in Reading.  Set Status to
  172. ON if Reading <= Setpoint.
  173.  
  174.   Descendant object types:
  175. None.      }
  176.  
  177. { Specification for Pump class **************************
  178.  
  179.   Variables:
  180.             FlowRate : real;
  181.             A number representing gpm flow when pump is
  182.             ON.  NOTE: THIS IS A *VERY* ROUGH APPROXIMATION
  183.             OF PUMP BEHAVIOR!
  184.  
  185.   Procedures:
  186.             .Init( ATag : String12; AStatus : boolean;
  187.       AFlow : real );
  188.             Storage as follows:
  189.   ATag -> TagNumber
  190.   AStatus -> Status
  191.   AFlow -> FlowRate
  192.  
  193.   Functions:
  194.             .Flow : real;
  195.             Returns the value stored in FlowRate.
  196.  
  197.   Descendant object types:
  198.             None.       }
  199.  
  200. unit Tags;
  201.  
  202. interface
  203.  
  204. uses Crt; { for KeyPressed }
  205.  
  206. const
  207.  
  208. ON  = true;
  209. OFF = false;
  210. MinR = 0;       { Minimum number of counts in an analog
  211. input }
  212. MaxR = 4095;    { Maximum number of counts in an analog
  213. input }
  214.  
  215. var
  216.     f : text;  {predefined file type}
  217.  
  218. type
  219.  
  220. Resolution = 0..4095;  { Range for analog input }
  221. String12 = string[12];
  222.  
  223.  
  224. Tag = object
  225.       TagNumber : String12;
  226.       procedure Init( ATag : String12 );
  227.       end;
  228.  
  229. Digital = object(Tag)
  230.           Status : boolean;
  231.           procedure Init( ATag : String12; AStatus :
  232. boolean );
  233.           procedure PutStatus( AStatus : boolean );
  234.           function GetStatus : boolean;
  235.           end;
  236.  
  237. Analog = object(Tag)
  238.          Value : Resolution;
  239.          ZeroVal : real;
  240.          MaxVal : real;
  241.          Slope  : real;
  242.          procedure Init( ATag : String12; AValue :
  243. Resolution;
  244.             Min, Max : real );
  245.          procedure PutValue( AValue : real );
  246.          function GetValue : real;
  247.          end;
  248.  
  249. DOutput = object(Digital)
  250.           end;
  251.  
  252. Pump = object(DOutput)
  253.        FlowRate : real;
  254.        procedure Init( ATag : String12; AStatus : boolean;
  255.                        AFlow : real );
  256.        function Flow : real;
  257.        end;
  258.  
  259.  
  260. DInput = object(Digital)
  261.             Setpoint  : real;
  262.             Reading   : real;
  263.             procedure PutSetpoint( NewSetpoint : real );
  264.             end;
  265.  
  266. HiSwitch = object(DInput)
  267.            procedure Init( ATag : string;
  268.             ASetpoint : real;
  269.             AReading : real);
  270.            procedure PutReading( NewReading : real );
  271.            end;
  272.  
  273. LoSwitch = object(DInput)
  274.            procedure Init( ATag : string;
  275.             ASetpoint : real;
  276.             AReading : real);
  277.            procedure PutReading( NewReading : real );
  278.            end;
  279.  
  280. FSwitch = object
  281.           State : boolean;
  282.           procedure Init( InitState : boolean );
  283.           procedure On;
  284.           procedure Off;
  285.           function IsOn : boolean;
  286.           function IsOff : boolean;
  287.           end;
  288.  
  289.  
  290. function HtToPSI( Height : real ) : real;
  291.  
  292. function FlowToDeltaHt( Flow : real ) : real;
  293.  
  294. var
  295.    Quiet : FSwitch;
  296.  
  297. implementation
  298.  
  299. procedure Tag.Init( ATag : String12 );
  300. begin
  301.      TagNumber := ATag;
  302. end;
  303.  
  304. procedure Digital.Init( ATag : String12; AStatus : boolean
  305. );
  306. begin
  307.      Tag.Init( ATag );
  308.      Status := AStatus;
  309. end;
  310.  
  311. procedure Digital.PutStatus( AStatus : boolean );
  312. begin
  313.      Status := AStatus;
  314. end;
  315.  
  316. function Digital.GetStatus : boolean;
  317. begin
  318.      if (Status = ON) and (Quiet.IsOff) then
  319.         writeln( f, TagNumber, ' is ON.' )
  320.      else
  321.         if (Quiet.IsOff) then
  322.            writeln( f, TagNumber, ' is OFF.' );
  323.      GetStatus := Status;
  324. end;
  325.  
  326. procedure Pump.Init( ATag : String12; AStatus : boolean;
  327. AFlow : real );
  328. begin
  329.      Digital.Init( ATag, AStatus );
  330.      FlowRate := AFlow;
  331. end;
  332.  
  333. function Pump.Flow : real;
  334. begin
  335.      Flow := FlowRate;
  336. end;
  337.  
  338. procedure Analog.Init( ATag : String12;
  339.           AValue : Resolution;
  340.           Min, Max : real );
  341. begin
  342.      Tag.Init( ATag );
  343.      Value := AValue;
  344.      MaxVal := Max;
  345.      ZeroVal := Min;
  346.      Slope := (Max-Min)/(MaxR-MinR);
  347. end;
  348.  
  349. procedure Analog.PutValue( AValue : real );
  350. begin
  351.      if AValue > MaxVal then
  352.         AVAlue := MaxVal
  353.      else
  354.         if AValue < ZeroVal then
  355.            AValue := ZeroVal;
  356.      Value := Round((AValue - ZeroVal)/Slope);
  357. end;
  358.  
  359. function Analog.GetValue : real;
  360. begin
  361.      GetValue := Slope*Value + ZeroVal;
  362. end;
  363.  
  364. procedure DInput.PutSetpoint( NewSetpoint : real );
  365. begin
  366.      Setpoint := NewSetpoint;
  367. end;
  368.  
  369. procedure LoSwitch.Init( ATag : string;
  370.             ASetpoint : real;
  371.             AReading : real);
  372. begin
  373.      Tag.Init( ATag );
  374.      DInput.PutSetpoint( ASetpoint );
  375.      PutReading( AReading );
  376. end;
  377.  
  378. procedure LoSwitch.PutReading( NewReading : real );
  379. begin
  380.      Reading := NewReading;
  381.      if Reading <= Setpoint then
  382.         Status := true
  383.      else
  384.         Status := false;
  385. end;
  386.  
  387. procedure HiSwitch.Init( ATag : string;
  388.             ASetpoint : real;
  389.             AReading : real);
  390. begin
  391.      Tag.Init( ATag );
  392.      DInput.PutSetpoint( ASetpoint );
  393.      PutReading( AReading );
  394. end;
  395.  
  396. procedure HiSwitch.PutReading( NewReading : real );
  397. begin
  398.      Reading := NewReading;
  399.      if Reading >= Setpoint then
  400.         Status := true
  401.      else
  402.         Status := false;
  403. end;
  404.  
  405. procedure FSwitch.Init( InitState : boolean );
  406. begin
  407.      State := InitState;
  408.      if State = false then  { If we want output}
  409.         Rewrite( f )      { Open file f }
  410.      else
  411.         begin
  412.         Rewrite( f );     { Open file f }
  413.         Close( f );       { and close it }
  414.         end;
  415. end;
  416.  
  417. procedure FSwitch.On;
  418. begin
  419.      if State = false then
  420.         begin
  421.         State := true;
  422.         Close( f );
  423.         end;
  424. end;
  425.  
  426. procedure FSwitch.Off;
  427. begin
  428.      if State = true then
  429.         begin
  430.         State := false;
  431.         Append( f );
  432.         end;
  433. end;
  434.  
  435. function FSwitch.IsOn : boolean;
  436. begin
  437.      if State = true then
  438.         IsOn := true
  439.      else
  440.         IsOn := false;
  441. end;
  442.  
  443. function FSwitch.Isoff : boolean;
  444. begin
  445.      IsOff := not IsOn;
  446. end;
  447.  
  448. { HtToPSI converts a height (of a column of water) into a
  449. pressure.
  450.   The math is pretty simple:  A column of water 2.31 feet
  451. high exerts
  452.   a force of one pound per square inch at the bottom. }
  453.  
  454. function HtToPSI( Height : real ) : real;
  455. begin
  456.      HtToPSI := Height/2.31;
  457. end;
  458.  
  459. { FlowToDeltaHt converts a flow into (or out of) our system
  460. into a
  461.   change in height in the tank.
  462.   The math is as follows:  Divide the flow, in gpm, by 7.48
  463. gal/cu.ft.
  464.   to get the number of cubic feet pumped per minute.
  465. Divide this
  466.   number by the volume of 1 vertical foot of the tank,
  467. which is
  468.   the radius squared times 'pi' (15*15*3.1416). }
  469.  
  470. function FlowToDeltaHt( Flow : real ) : real;
  471. begin
  472.      FlowToDeltaHt := Flow/(7.48 * 706) ;
  473. end;
  474.  
  475. { initialization code }
  476. begin
  477.  
  478. Assign( f, ParamStr(1) );
  479.  
  480. Quiet.Init(OFF);
  481.  
  482. end.
  483.  
  484. { Listing 3-1 }
  485.